<template>
  <div class="app-container">
    <el-form :model="queryParams"  style="background-color: white;padding-top: 20px" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="擅长标签" prop="scLabel">-->
<!--        <el-input-->
<!--          v-model="queryParams.scLabel"-->
<!--          placeholder="请输入擅长标签"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
          >删除</el-button>
        </el-col>
      </el-row>
    </el-form>


      <el-table v-loading="loading" :data="doctorList" :header-cell-style="{ fontWeight: 'bold' }"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="医生ID" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="头像" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <div class="demo-image__preview">
            <el-image style="width: 36px; height: 36px" :src="scope.row.image"
                      :preview-src-list="[scope.row.image]" />
          </div>
        </template>
      </el-table-column>

      <el-table-column label="职位" align="center" prop="zw" />
<!--      <el-table-column label="介绍" align="center" prop="info" />-->
<!--      <el-table-column label="擅长" align="center" prop="scInfo" />-->
<!--      <el-table-column label="简介" align="center" prop="jjInfo" />-->
      <el-table-column label="擅长标签" align="center" prop="scLabel" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="评分" align="center" prop="score" />
      <el-table-column label="问诊量" align="center" prop="num" />
      <el-table-column label="是否是三甲" align="center" prop="isSj" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isSj == 1" type="success">是</el-tag>
          <el-tag v-if="scope.row.isSj == 0" type="danger">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="科室" align="center" prop="ks" />
<!--      <el-table-column label="状态" align="center" prop="status" />-->
<!--      <el-table-column label="管理员备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

<!--    <pagination-->
<!--      v-show="total>0"-->
<!--      :total="total"-->
<!--      :page.sync="queryParams.pageNum"-->
<!--      :limit.sync="queryParams.pageSize"-->
<!--      @pagination="getList"-->
<!--    />-->

    <!-- 添加或修改医生信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>


        <el-form-item
          label="头像"
          prop="image"
          :rules="[{ required: true, message: '请上传图文封面', trigger: 'change' }]"
        >
          <div class="upLoadPicBox" @click="modalPicTap('1')">
            <div v-if="form.image" class="pictrue"><img :src="form.image" /></div>
            <div v-else class="upLoad">
              <i class="el-icon-camera cameraIconfont" />
            </div>
          </div>
        </el-form-item>
<!--        <el-form-item label="头像" prop="image">-->
<!--          <image-upload v-model="form.image"/>-->
<!--        </el-form-item>-->
        <el-form-item label="职位" prop="zw">
          <el-input v-model="form.zw" placeholder="请输入职位" />
        </el-form-item>
        <el-form-item label="介绍" prop="info">
          <el-input v-model="form.info"   type="textarea" placeholder="请输入介绍" />
        </el-form-item>
        <el-form-item label="擅长" prop="scInfo">
          <el-input v-model="form.scInfo"  type="textarea" placeholder="请输入擅长" />
        </el-form-item>
        <el-form-item label="简介" prop="jjInfo">
          <el-input v-model="form.jjInfo"   type="textarea"  placeholder="请输入简介" />
        </el-form-item>
        <el-form-item label="擅长标签" prop="scLabel">
          <el-input v-model="form.scLabel" placeholder="请输入擅长标签" />
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input-number v-model="form.price"  :min="1" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="评分" prop="score">
          <el-input-number v-model="form.score"  :min="1"  placeholder="请输入评分" />
        </el-form-item>
        <el-form-item label="问诊量" prop="num">
          <el-input-number  v-model="form.num"  :min="1"  placeholder="请输入问诊量" />
        </el-form-item>
        <el-form-item label="是否是三甲" prop="isSj">
          <el-select v-model="form.isSj" placeholder="请选择是否是三甲">
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="科室" prop="ks">
          <el-input v-model="form.ks" placeholder="请输入科室" />
        </el-form-item>
<!--        <el-form-item label="管理员备注" prop="remark">-->
<!--          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDoctor, getDoctor, delDoctor, addDoctor, updateDoctor } from "@/api/doctor";

export default {
  name: "Doctor",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医生信息表格数据
      doctorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        image: null,
        zw: null,
        info: null,
        scInfo: null,
        jjInfo: null,
        scLabel: null,
        price: null,
        score: null,
        num: null,
        isSj: null,
        ks: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        zw: [
          { required: true, message: "职位不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "订单状态不能为空", trigger: "change" }
        ],
        image: [
          { required: true, message: "图文封面不能为空", trigger: "change" }
        ],
        num: [
          { required: true, message: "问诊量不能为空", trigger: "blur" }
        ],
        score: [
          { required: true, message: "评分不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "价格不能为空", trigger: "blur" }
        ],
        ks: [
          { required: true, message: "科室不能为空", trigger: "blur" }
        ],
        isSj: [
          { required: true, message: "是否是三甲不能为空", trigger: "change" }
        ]

      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    modalPicTap(tit) {
      const _this = this;
      this.$modalUpload(
        function (img) {
          console.log(img,"kkkkkkkkkkkkkk");
          _this.form.image = img[0].sattDir;
        },
        tit,
        'content',
      );
    },
    /** 查询医生信息列表 */
    getList() {
      this.loading = true;
      listDoctor(this.queryParams).then(response => {
        console.log(response);
        this.doctorList = response.list;
        console.log( this.doctorList,"mmmmmmmmmmm");
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        image: null,
        zw: null,
        info: null,
        scInfo: null,
        jjInfo: null,
        scLabel: null,
        price: null,
        score: null,
        num: null,
        isSj: null,
        ks: null,
        createTime: null,
        status: null,
        remark: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加医生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDoctor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改医生信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            console.log(this.form.image)
            if(this.form.image){
              this.form.image = this.form.image.replaceAll("http://127.0.0.1:8080/","");
              console.log(this.form.image)
            }
            console.log(this.form.image)
            updateDoctor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDoctor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除医生信息编号为"' + ids + '"的数据项？').then(function() {
        return delDoctor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/doctor/export', {
        ...this.queryParams
      }, `doctor_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>


<style scoped lang="scss">
.pos-order-goods {
  padding: 0 0.3rem;
  background-color: #fff;
}
.pos-order-goods .goods {
  height: 1.85rem;
}
.pos-order-goods .goods ~ .goods {
  border-top: 1px dashed #e5e5e5;
}
.pos-order-goods .goods .picTxt {
  width: 5.15rem;
}
.pos-order-goods .goods .picTxt .pictrue {
  width: 1.3rem;
  height: 1.3rem;
}
.pos-order-goods .goods .picTxt .pictrue img {
  width: 100%;
  height: 100%;
  border-radius: 0.06rem;
}
.pos-order-goods .goods .picTxt .text {
  width: 3.65rem;
  height: 1.3rem;
}
.pos-order-goods .goods .picTxt .text .info {
  font-size: 0.28rem;
  color: #282828;
}
.pos-order-goods .goods .picTxt .text .attr {
  font-size: 0.2rem;
  color: #999;
  height: 0.8rem;
  line-height: 0.8rem;
  width: 5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pos-order-goods .goods .money {
  width: 1.64rem;
  text-align: right;
  font-size: 0.28rem;
  height: 1.3rem;
}
.pos-order-goods .goods .money .x-money {
  color: #282828;
}
.pos-order-goods .goods .money .num {
  color: #ff9600;
  margin: 0.05rem 0;
}
.pos-order-goods .goods .money .y-money {
  color: #999;
  text-decoration: line-through;
}
.pos-order-list {
  background: #f5f5f5;
  margin-top: -50px;
}
.pos-order-list .nav {
  width: 100%;
  height: 0.96rem;
  background-color: #fff;
  font-size: 0.3rem;
  color: #282828;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 66;
}
.pos-order-list .nav .item.on {
  color: #2291f8;
}
.pos-order-list .list {
  margin-top: 0.2rem;
}
.pos-order-list .list .item {
  background-color: #fff;
  width: 100%;
}
.pos-order-list .list .item ~ .item {
  margin-top: 0.24rem;
}
.pos-order-list .list .item .order-num {
  height: 1.24rem;
  border-bottom: 1px solid #eee;
  font-size: 0.3rem;
  font-weight: bold;
  color: #282828;
  padding: 0 0.3rem;
}
.pos-order-list .list .item .order-num .time {
  font-size: 0.26rem;
  font-weight: normal;
  color: #999;
  margin-top: -0.4rem;
}
.pos-order-list .list .item .operation {
  padding: 0.2rem 0.3rem;
  margin-top: 0.03rem;
}
.pos-order-list .list .item .operation .more {
  position: relative;
}
.pos-order-list .list .item .operation .icon-gengduo {
  font-size: 0.5rem;
  color: #aaa;
}

.pos-order-list .list .item .operation .order .arrow {
  width: 0;
  height: 0;
  border-left: 0.11rem solid transparent;
  border-right: 0.11rem solid transparent;
  border-top: 0.2rem solid #e5e5e5;
  position: absolute;
  left: 0.15rem;
  bottom: -0.18rem;
}
.pos-order-list .list .item .operation .order .arrow:before {
  content: '';
  width: 0;
  height: 0;
  border-left: 0.07rem solid transparent;
  border-right: 0.07rem solid transparent;
  border-top: 0.2rem solid #fff;
  position: absolute;
  left: -0.07rem;
  bottom: 0;
}
.pos-order-list .list .item .operation .order {
  width: 2rem;
  background-color: #fff;
  border: 1px solid #eee;
  border-radius: 0.1rem;
  position: absolute;
  top: -1rem;
  z-index: 9;
}
.pos-order-list .list .item .operation .order .items {
  height: 0.77rem;
  line-height: 0.77rem;
  text-align: center;
}
.pos-order-list .list .item .operation .order .items ~ .items {
  border-top: 1px solid #f5f5f5;
}

.pos-order-list .list .item .operation .bnt {
  font-size: 0.28rem;
  color: #5c5c5c;
  width: 1.7rem;
  height: 0.6rem;
  border-radius: 0.3rem;
  border: 1px solid #bbb;
  text-align: center;
  line-height: 0.6rem;
}
.pos-order-list .list .item .operation .bnt ~ .bnt {
  margin-left: 0.14rem;
}
.public-total {
  font-size: 0.28rem;
  color: #282828;
  border-top: 1px solid #eee;
  height: 0.92rem;
  line-height: 0.92rem;
  text-align: right;
  padding: 0 0.3rem;
  background-color: #fff;
}
.public-total .money {
  color: #ff4c3c;
}
</style>
